package org.firestorm.traficforecast.database;

public class Hedge {
	private double middle;
	private double very;
	private double more;
	private double possibly;
	private double less;
	
	private double[] val;

	public static void main(String[] args) {
		Hedge hedge = HedgeDAO.getHedge();
		System.out.println(hedge.getValue("rat cao", 541));
		System.out.println(hedge.val[3]);
	}

	public Hedge() {

	}

	public Hedge(double midd, double very, double more, double pos, double less) {
		this.middle = midd;
		this.very = very;
		this.more = more;
		this.possibly = pos;
		this.less = less;
		
		this.val = new double[8];
		this.val[0] = this.getVery() * this.getMiddle();
		this.val[1] = this.val[0] + this.getMore() * this.getMiddle();
		this.val[2] = this.val[1] + this.getPossibly() * this.getMiddle();
		this.val[3] = this.val[2] + this.getLess() * this.getMiddle();
		this.val[4] = this.val[3] + this.getLess() * (1 - this.getMiddle());
		this.val[5] = this.val[4] + this.getPossibly() * (1 - this.getMiddle());
		this.val[6] = this.val[5] + this.getMore() * (1 - this.getMiddle());
		this.val[7] = this.val[6] + this.getVery() * (1 - this.getMiddle());
	}

	public double getMiddle() {
		return middle;
	}

	public void setMiddle(double middle) {
		this.middle = middle;
	}

	public double getVery() {
		return very;
	}

	public void setVery(double very) {
		this.very = very;
	}

	public double getMore() {
		return more;
	}

	public void setMore(double more) {
		this.more = more;
	}

	public double getPossibly() {
		return possibly;
	}

	public void setPossibly(double possibly) {
		this.possibly = possibly;
	}

	public double getLess() {
		return less;
	}

	public void setLess(double less) {
		this.less = less;
	}

	public int getValue(String numthen, int dom) {
		if (numthen.contains("rat")) {
			if (numthen.contains("thap")) {
				return (int)Math.round(0.5*this.val[0]*dom);
			}else{
				return (int)Math.round(0.5*(this.val[7] + this.val[6])*dom);
			}
		} else if (numthen.contains("hon")) {
			if (numthen.contains("thap")) {
				return (int)Math.round(0.5*(this.val[0] + this.val[1])*dom);
			}else{
				return (int)Math.round(0.5*(this.val[6] + this.val[5])*dom);
			}
		} else if (numthen.contains("kha nang")) {
			if (numthen.contains("thap")) {
				return (int)Math.round(0.5*(this.val[2] + this.val[1])*dom);
			}else{
				return (int)Math.round(0.5*(this.val[5] + this.val[4])*dom);
			}
		} else {
			if (numthen.contains("thap")) {
				return (int)Math.round(0.5*(this.val[3] + this.val[2])*dom);
			}else{
				return (int)Math.round(0.5*(this.val[4] + this.val[3])*dom);
			}
		}
	}

}
